package com.food.eat.controller;


import com.food.eat.config.OrderMintor;
import com.food.eat.enums.PayMethod;
import com.food.eat.mapper.OrderMapper;
import com.food.eat.pojo.OrderBase;
import com.food.eat.pojo.bo.OrderDto;
import com.food.eat.pojo.vo.SumbitOrderVo;
import com.food.eat.util.FoodResultJson;
import io.swagger.annotations.Api;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Random;

@Api(value = "订单案例编写", tags = {"订单案例编写"})
@RequestMapping("/orderBase")
@RestController
public class OrderExampleController {

//
    @Resource
    private OrderMapper orderMapper;

    @Resource
    private OrderMintor orderMintor;

    /**
     *
     * @param orderBase
     * @return
     */
    @PostMapping(value = "addOrder")
    public FoodResultJson create(@RequestBody OrderBase orderBase) {

        //从10-20获取随机值作为延时周期，单位为秒
       int timeCycle= new Random().nextInt(10)+10;
        orderBase.setTimeCycle((long) timeCycle);
        orderMapper.insertOrder(orderBase);
        orderMintor.addQueue(new OrderDto(orderBase.getOrderId(),(long) timeCycle));
        return FoodResultJson.ok(orderBase);
    }


    public static void main(String[] args) {
        int timeCycle= new Random().nextInt(10)+10;

        System.out.println(timeCycle);
    }

}
